<template>
  <div class="mod-menu">
    <el-form :inline="true" :model="pamars">
      <el-form-item label="服务名称">
        <el-input v-model="pamars.title" placeholder="请输入服务名称" clearable></el-input>
      </el-form-item>
      <el-form-item label="所属店铺">
        <el-input v-model="pamars.shop_name" placeholder="请输入所属店铺" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getListOne()">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="tableData" row-key="Id" border style="width: 100%; ">
      <el-table-column header-align="center" align="center" width="80" label="编号">
        <template slot-scope="scope"><span>{{scope.$index+(pamars.page - 1) * pamars.page + 1}} </span></template>
      </el-table-column>
      <el-table-column prop="cover" align="center" label="服务图片">
        <template slot-scope="scope">
          　　　　<el-popover placement="top-start" trigger="click">
            <a :href="scope.row.cover" target="_blank" title="查看最大化图片"><img :src="scope.row.cover" style="width: 300px;height: 300px" /></a>
            <img slot="reference" :src="scope.row.cover" @click="$openImg(scope.row.cover)" style="width: 50px;height: 50px; cursor:pointer" />
          </el-popover>
          <!-- <el-image class="table-img" :src="scope.row.cover" :preview-src-list="[scope.row.cover]">
        		</el-image> -->
        </template>
      </el-table-column>
      <el-table-column prop="title" align="center" label="服务名称">
      </el-table-column>
      <el-table-column prop="shop_name" align="center" label="所属店铺">
      </el-table-column>
      <el-table-column prop="sale_price" align="center" label="价格">
      </el-table-column>
      <el-table-column prop="sort" align="center" label="排序">
      </el-table-column>
      <el-table-column prop="real_sale_num" align="center" label="销量">
      </el-table-column>

      <el-table-column prop="verify_status" align="center" :formatter="statusFormatter" label="审核状态">
        <template slot-scope="scope">
          <el-tag type="warning" slot="reference" v-if="scope.row.verify_status==0">待审核</el-tag>
          <el-tag type="success" slot="reference" v-if="scope.row.verify_status==1">审核通过</el-tag>

          <el-popover placement="top-start" title="审核不通过" trigger="hover">
            <div style="width:800px">
              不通过理由:{{scope.row.verify_remark}}
            </div>
            <el-tag type="danger" slot="reference" v-if="scope.row.verify_status==2">审核不通过</el-tag>
          </el-popover>
          <div style="margin-top: 10px; width:100%;overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;" v-if="scope.row.verify_status==2&&scope.row.verify_remark">
            {{'不通过理由:'+scope.row.verify_remark}}
          </div>

        </template>
      </el-table-column>
      <el-table-column fixed="right" header-align="center" align="center" label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id,'view')">查看</el-button>
          <el-button type="text" size="small" @click="showDialog('check',scope.row.id)">审核</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pamars.limit" :page-sizes="[10, 20, 50, 100]" :page-size="pamars.page" :total="totalPage" layout="total, sizes, prev, pager, next, jumper"></el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <view-or-update v-if="dialogVisible" ref="dialogView" @result="result"></view-or-update>
  </div>
</template>

<script>
import seviceApi from '@/api/serviceApi.js'
import serviceApione from '@/api/serviceApione.js'
import ViewOrUpdate from './service-update'
export default {
  components: {
    ViewOrUpdate
  },
  data () {
    return {
      dataForm: {},
      tableData: [],
      dataListLoading: false,
      addOrUpdateVisible: false,
      setShareBenefit: false, // 分润设置
      pamars: {
        page: 1,
        limit: 10
      },
      totalPage: 0,
      dialogVisible: false
    }
  },
  mounted () {
    this.getList()
  },
  methods: {
    result () {
      this.dialogVisible = false
      this.getList()
    },
    handleClickDelete (row) {
      this.$confirm(`是否删除服务 [ ${row.title} ] ?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        serviceApione.delServiceGoods(row.id).then(res => {
          console.log(res)
          if (res.data && res.data.code == 200) {
            this.$message.success('删除成功！')
            this.getList()
          }
        })
      }).catch(() => { })
    },
    getList () {
      seviceApi.getPlatformServiceList(this.pamars).then(res => {
        if (res && res.data.code == 200) {
          this.tableData = res.data.page.list
          this.totalPage = res.data.page.totalCount
        }
      })
    },
    getListOne () {
      this.pamars.page = 1
      this.getList()
    },

    // 每页数
    sizeChangeHandle (val) {
      this.pamars.limit = val
      this.getList()
    },
    // 当前页
    currentChangeHandle (val) {
      this.pamars.page = val
      this.getList()
    },
    // 审核动态
    statusFormatter (row, column) {
      let status = row.verify_status
      if (status === 0) {
        return '待审核'
      } else if (status === 1) {
        return '审核通过'
      } else if (status === 1) {
        return '审核不通过'
      } else {
        return '-'
      }
    },
    // 新增 / 修改
    addOrUpdateHandle (id, type) {
      this.$router.push({
        path: '/send-platformService',
        query: {
          id: id,
          type: type
        }
      })
      // this.setShareBenefit = true
      // this.$nextTick(() => {
      //   this.$refs.serveAddUpdate.init(id)
      // })
    },

    // 审核
    showDialog (type, row) {
      this.dialogVisible = true
      this.$nextTick(() => {
        this.$refs.dialogView.init(type, row)
      })
    }
  }
}
</script>
